package com.jxzn.locust.config;

import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonBeanProcessor;

public class HibernateJsonBeanProcessor implements JsonBeanProcessor {

    @Override
    public JSONObject processBean(Object arg0, JsonConfig arg1) {
        LazyInitializer lazyInitializer = ((HibernateProxy) arg0).getHibernateLazyInitializer();
        if (lazyInitializer.isUninitialized()) {
            return JSONObject.fromObject(lazyInitializer.getIdentifier());
        }
        return new JSONObject();
    }

}
